<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>采购单查询</title>
<link href="/css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="../script/My97DatePicker/WdatePicker.js" ></script>
<script type="text/javascript" src="../script/jquery-1.8.1.min.js"></script>
<script type="text/javascript">
	var currentPage=1;
	var poId;
	var startDate;
	var endDate;
	var venderCode;
	var payType;
	var status;
	function test(){
		poId = $("[name=poId]").val();
		startDate = $("[name=startDate]").val();
		endDate = $("[name=endDate]").val();
		venderName = $("[name=venderName]").val();
		payType = $("[name=payType]:checked").val();
		if(payType!=1&&payType!=2&&payType!=3){//未选中
			payType="";
		}
		status = $("[name=status]:checked").val();
		if(status!=1&&status!=2&&status!=3&&status!=4&&status!=5){//未选中
			status="";
		}
		query();
	}
	function goPage(obj){
		if(obj=='first'){
			currentPage=1;
			test();
		}else if(obj=='front'){
			if(currentPage==1){
				alert("已经是首页了");
			}else{
				currentPage-=1;
				test();
			} 
		}else if(obj=='next'){
			if(currentPage==$("#ap").text()){
				alert("已经是末页了");
			}else{
				currentPage+=1;
				test();
			}
		}else{
			if(currentPage+1<=$("#ap").text()){
				currentPage=$("#ap").text();
				test();
			}
		}
	}
	function showAllDetail(obj){
		window.location.href="../main/pomain/ShowAllPomainDetail?poId="+obj;
	}
	function query(){
		$.ajax({
			type:'post',
			url:'../main/pomain/queryPomain',
			data:{poId:poId,startDate:startDate,endDate:endDate,venderName:venderName,
				payType:payType,status:status,currentPage:currentPage},
			dataType:'json', //获得的json格式的数据将被转换成JS对象
			success:function(msg){
				$("#t").children().remove();//添加数据之前先清空数据
					if(msg.datalist==''){
						$("#t").append("<td colspan='10' align='center'><span style='color:red;font-size:20px'>没有结果,请修改查询条件</span></td>");
					}else{
						for(var i=0;i<msg.dataList.length;i++){ 
							if(msg.dataList[i].payType==1){
								msg.dataList[i].payType="货到付款";
							}else if(msg.dataList[i].payType==2){
								msg.dataList[i].payType="款到发货";
							}else if(msg.dataList[i].payType==3){
								msg.dataList[i].payType="预付款到发货";
							}
							if(msg.dataList[i].status==1){
								msg.dataList[i].status="新增";
							}else if(msg.dataList[i].status==2){
								msg.dataList[i].status="已付款";
							}else if(msg.dataList[i].status==3){
								msg.dataList[i].status="已预付";
							}else if(msg.dataList[i].status==4){
								msg.dataList[i].status="已入库";
							}else if(msg.dataList[i].status==5){
								msg.dataList[i].status="已了结";
							}
							$("#t").append("<tr align='center'><td ondblclick='showAllDetail("+msg.dataList[i].poId+")'><span style='color:blue'>"+msg.dataList[i].poId+"</span></td><td>"+msg.dataList[i].createTime+"</td><td>"
							+msg.dataList[i].venderName+"</td><td>"+msg.dataList[i].account+"</td><td>"+msg.dataList[i].tipFee+
							"</td><td>"+msg.dataList[i].productTotal+"</td><td>"+msg.dataList[i].poTotal+"</td><td>"+msg.dataList[i].payType+
							"</td><td>"+msg.dataList[i].prePayFee+"</td><td>"+msg.dataList[i].status+"</td></tr>");
					}
				}
				//将当前和总页数放在节点对象中
				$("#cp").text(msg.currentPage);
				$("#ap").text(msg.pageCount);
			}
		});
	}
	function showVender(){
		document.getElementById("vender").style.display="block";
		document.getElementById("main").style.display="none";
		queryVender();
	}
	var currentVenderPage=1;
	function queryVender(){
		$.ajax({
			type:"post",
			url:"../main/pomain/ListAllVender",
			data:{currentPage:currentVenderPage},
			dataType:"json",
			success:function(msg){
				$("#tvender").children().remove();
				for(var i=0;i<msg.dataList.length;i++){ 
					$("#tvender").append("<tr align='center'><td>"+msg.dataList[i].venderCode+"</td><td>"
							+msg.dataList[i].name+"</td><td><input type='button' value='选择' onclick='chooseVender(this)'/></td></tr>");
				}
				$("#vc").text(msg.currentPage);
				$("#va").text(msg.pageCount);
			}
		});
	}
	function chooseVender(obj){
		$("[name=venderName]").val(obj.parentNode.parentNode.cells[1].innerHTML);
		$("[name=venderCode]").val(obj.parentNode.parentNode.cells[0].innerHTML);
		document.getElementById("vender").style.display="none";
		document.getElementById("main").style.display="block";
	}
	function goback(){
		document.getElementById("vender").style.display="none";
		document.getElementById("main").style.display="block";
		document.getElementById("product").style.display="none";
	}
	function vendergoPage(obj){
		if(obj=='first'){
			currentVenderPage=1;
			queryVender();
		}else if(obj=='front'){
			if(currentVenderPage==1){
				alert("已经是首页了");
			}else{
				currentVenderPage-=1;
				queryVender();
			} 
		}else if(obj=='next'){
			if(currentVenderPage==$("#ap").text()){
				alert("已经是末页了");
			}else{
				currentVenderPage+=1;
				queryVender();
			}
		}else{
			if(currentVenderPage+1<=$("#ap").text()){
				currentVenderPage=$("#ap").text();
				queryVender();
			}
		}
	}
</script>
</head>
<body bgcolor="#ffffff" >
<div id="main">
	<table width="100%"  border="0" cellpadding="0" cellspacing="0">
	  <tr>
	    <td nowrap class="title1">您的位置：工作台面－－采购管理－－采购单查询</td>
	  </tr>
	</table>
	<form name="form">
	<table width="100%"  border="0"  >
	  <tr>
	    <td width="50%" align="right">采购单编号&nbsp;&nbsp;&nbsp;</td>
	    <td width="50%"><input type="text" name="poId" /></td>
	  </tr>
	  <tr>
	    <td align="right">开始日期&nbsp;&nbsp;&nbsp;</td>
	    <td width="50%"><input type="text" name="startDate" class="Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,readOnly:true})" /></td>
	  </tr>
	  <tr>
	  	<td align="right">截止日期&nbsp;&nbsp;&nbsp;</td>
	    <td width="50%"><input type="text" name="endDate" class="Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false,readOnly:true})" /></td>
	  </tr>
	  <tr>
	  	<td align="right">供应商选择&nbsp;&nbsp;&nbsp;</td>
	    <td width="50%"><input type="text" size="15" name="venderName" onclick="showVender()"/><input type="text" name="venderCode" hidden/></td>
	  </tr>
	  <tr>
	  	<td align="right">付款方式&nbsp;&nbsp;&nbsp;</td>
	    <td width="50%">
		    <input type="radio" name="payType" value=1 />货到付款
		    <input type="radio" name="payType" value=2 />款到发货
		    <input type="radio" name="payType" value=3 />预付款到发货
		</td>
	  </tr>
	  <tr>
	  	<td align="right">处理状态&nbsp;&nbsp;&nbsp;</td>
	    <td width="50%">
 			<input type="radio" name="status" value=1 />新增
		    <input type="radio" name="status" value=2 />已付款
		    <input type="radio" name="status" value=3 />已预付
		    <input type="radio" name="status" value=4 />已入库
		    <input type="radio" name="status" value=5 />已了结
		</td>
	  </tr>
	</table><br/>
	<center>
		<input type="button" value="查询" onclick="test()"/>&nbsp;&nbsp;&nbsp;
		<input type="reset" value="重置"/>
	</center>
	</form>
	<center><h3>↓↓↓↓ 查询结果 ↓↓↓↓</h3></center>
	<table width="100%"  border="0" align="center" cellspacing="1" class="c">
		<tr>
			<td class="title1">采购单编号</td>
			<td class="title1">创建日期</td>
			<td class="title1">供应商名称</td>
			<td class="title1">创建用户</td>
			<td class="title1">附加费用</td>
			<td class="title1">采购产品总价</td>
			<td class="title1">采购单总价格</td>
			<td class="title1">付款方式</td>
			<td class="title1">最低预付款金额</td>
			<td class="title1">处理状态</td>
		</tr>
		<tbody id="t">
		<tr><td colspan="10">&nbsp;</td></tr>
		    
	    </tbody>
	</table><br/>
<center>
	<input type="button" value="首页" onclick="goPage('first')"/>
	<input type="button" value="上一页" onclick="goPage('front')" />
	<input type="button" value="下一页" onclick="goPage('next')"/>
	<input type="button" value="末页" onclick="goPage('end')"/>
	当前第<span id="cp"></span>页
    	共<span id="ap"></span>页
</center>
</div>
 <div hidden id="vender">
	<table width="100%"  border="0" align="center" cellspacing="1" id="venderTable">
	  <tr>
	    <td class="toolbar"> 供应商编号 </td>
	    <td class="toolbar"> 供应商名称 </td>
	    <td class="toolbar"> 操作 </td>
	  </tr>
	  <tbody id="tvender">
	  	
	  </tbody>
	</table>
	<center><br/>
	<input type="button" value="首页" onclick="vendergoPage('first')"/>
	<input type="button" value="上一页" onclick="vendergoPage('front')" />
	<input type="button" value="下一页" onclick="vendergoPage('next')"/>
	<input type="button" value="末页" onclick="vendergoPage('end')"/>
	当前第<span id="vc"></span>页
    	共<span id="va"></span>页
    <input type="button" value="返回" onclick="goback()"/>
	</center>
</div>
</body>
</html>